﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ToyundaPhone.Helpers
{
	public class PlaylistEnumHelper
	{
		private System.Threading.Timer searchUpdateTimer;
		private Controls.SongListControl listControl;
		public int Delay { get; set; }

		public PlaylistEnumHelper(System.Threading.TimerCallback callback, Controls.SongListControl listControl, int delay = 500)
		{
			searchUpdateTimer = new System.Threading.Timer(callback);
			this.listControl = listControl;
			Delay = delay;
		}

		public void NotifyUpdate()
		{
			searchUpdateTimer.Change(Delay, 0);
		}

		public System.Collections.Generic.IEnumerable<Database.Playlist> GetEnumerator()
		{
			Database.SongDatabase db = (Application.Current as App).SongDatabase;
			if (listControl.Playlist == null) yield return null;
			foreach (var item in db.Playlists)
			{
				yield return item;
			}
		}
	}
}
